﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;

namespace ListBook
{
    public enum RComparer
    {
        BookName,
        Author,
        Price,
        Publication,
        Publishing
    }

    public class Comparer : IComparer<Book>
    {
        private RComparer _price;
        public Comparer(RComparer price)
        {
            _price = price;
        }

        public int Compare(Book x, Book y)
        {
            if (x == null && y == null) return 0;
            if (x == null) return -1;
            if (y == null) return 1;

            int result;
            switch (_price)
            {
                case RComparer.BookName:
                    result = string.Compare(x.BookName, y.BookName);
                    break;
                case RComparer.Author:
                    result = string.Compare(x.Author, y.Author);
                    break;
                //
                case RComparer.Price:
                    result = x.Price.CompareTo(y.Price);
                    break;

                case RComparer.Publication:
                    result = string.Compare(x.Publication, y.Publication);
                    break;
                case RComparer.Publishing:
                    result = string.Compare(x.Publishing, y.Publishing);
                    break;
                default:
                    throw new ArgumentException("Invalid Compare Type");
            }
            return result;
        }
    }
}
